<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="ic in page" :key="ic.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="ic.imgUrl"/>
          </div>
          <p class="icon-desc">{{ic.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>

  </div>
</template>

<script>
  export default {
    name: "HomeIcon",
    data() {
      return {
        swiperOption: {
          autoplay: false
        },
        iconList: [
          {
            id: '0001',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/41.png',
            desc: '这是我的唯品会是也',
          },
          {
            id: '0002',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/42.png',
            desc: 'LOL',
          },
          {
            id: '0003',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/43.png',
            desc: '赶集网',
          },
          {
            id: '0004',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/44.png',
            desc: 'UC',
          },
          {
            id: '0005',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/45.png',
            desc: '巨人',
          },
          {
            id: '0006',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/46.png',
            desc: '帽子',
          },
          {
            id: '0007',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/47.png',
            desc: '牛客',
          },
          {
            id: '0008',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/48.png',
            desc: '安卓',
          },
          {
            id: '0009',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/49.png',
            desc: 'C++',
          },
          {
            id: '0010',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/50.png',
            desc: 'Html',
          },
          {
            id: '0011',
            imgUrl: 'https://static.nowcoder.com/images/weblogo/color_logo/51.png',
            desc: 'Iphone',
          },
        ]
      }
    },
    computed: {
      pages() {
        const pages = [];
        this.iconList.forEach((item, index) => {
          const page = Math.floor(index / 8);
          if (!pages[page]) {
            pages[page] = []
          }
          pages[page].push(item)
        });
        return pages
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import "~styles/mixins.styl"
  .icons >>> .swiper-container
    overflow hidden
    height 0
    padding-bottom 50%

  .icons
    margin-top .1rem

  .icon
    position relative
    float left
    width 25%
    height 0
    padding-bottom 25%

    .icon-img
      position absolute
      top 0
      left 0
      right 0
      bottom .44rem
      padding .1rem
      box-sizing border-box

      .icon-img-content
        display block
        height 100%
        margin 0 auto

    .icon-desc
      position absolute
      left 0
      right 0
      bottom 0
      height .44rem
      line-height .44rem
      color #333
      text-align center
      margin-left 10%
      margin-right 10%
      ellipsis()


</style>
